# -*- coding: utf-8 -*-
# standard
import os
import sys
from datetime import datetime
from datetime import timedelta
from datetime import timezone

# third
from fastapi import APIRouter
from fastapi import Query as QueryParam
from pydantic import BaseModel

# local
_P_PATH =  os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if _P_PATH not in sys.path:
    sys.path.append(_P_PATH)
from toolbox.common_tools import logger
from toolbox.common_tools import INCLUDE_SCHEMA
from db.sqlalchemy_dbc import Resp
from functions.event_func import add
from functions.event_func import demo_func


"""
@Title:   demo 模块
@File: demo_view.py
@Author: walle 2024年12日29日 10时33分35秒
@Version: 1.0.0
@Desc: 
"""


router = APIRouter(prefix="/v1/demo")
EXT = {"tags": ["Demo"], "response_model": Resp, "include_in_schema": INCLUDE_SCHEMA}


@router.post("/add", summary="加法", **EXT)
async def demo_add_view(
    x: int = QueryParam(..., description="X"),
    y: int = QueryParam(..., description="Y"),
):
    add.apply_async(kwargs={"x": x, "y": y}, countdown=5)
    return {"message": "success"}


@router.post("/delay", summary="延迟执行", **EXT)
async def demo_delay_view(
):
    received_time = datetime.now()
    demo_func.apply_async(args=[received_time], countdown=10)
    return {"message": "success"}


if __name__ == '__main__':
    pass